package com.dengqi.mymodule.activity.loader.applists;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import java.util.List;

import androidx.annotation.Nullable;
import androidx.loader.content.AsyncTaskLoader;

/**
 * app加载器
 * Created by dell on 2019/5/7
 */
public class AppListLoader extends AsyncTaskLoader<List<ApplicationInfo>> {


    private AppListLoader(Context context) {
        super(context);
    }

    public static AppListLoader newInstance(Context context) {
        return new AppListLoader(context);
    }

    @Nullable
    @Override
    @SuppressLint("WrongConstant")
    public List<ApplicationInfo> loadInBackground() {
        PackageManager mPm = getContext().getPackageManager();
        List<ApplicationInfo> apps = mPm
                .getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES
                        | PackageManager.GET_DISABLED_COMPONENTS);
        return apps;
    }

}
